package dayu.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * @author dayu
 * @create 2018/12/13 15:04
 * @Description
 */
@Controller
@RequestMapping("/teacher")
public class TeacherController {

    @RequestMapping("/findAll")
    public String findAll(Model model) {
        Subject subject = SecurityUtils.getSubject();
        List<String> teachers = Arrays.asList("水浒传", "三国", "红楼梦");
        model.addAttribute("teachers", teachers);
        return "teacher/teacher";
    }

    @RequestMapping("/delete")
    public String delete(Model model, String name) {
        System.out.println("TeacherController.delete");
        System.out.println(name);
        Subject subject = SecurityUtils.getSubject();
        List<String> teachers = new ArrayList<>();
        teachers.add("水浒传");
        teachers.add("三国");
        teachers.add("红楼梦");
        Iterator<String> iterator = teachers.iterator();
        while (iterator.hasNext()) {
            if (iterator.next().equals(name)) {
                iterator.remove();
            }
        }

        model.addAttribute("teachers", teachers);
        return "teacher/teacher";
    }

}
